trigger trg_QuoteLineItem on QuoteLineItem (after delete, before insert) 
{
    
    Map<ID,ID> quoteIdMap = new Map<ID,ID>();
    Map<ID,ID> quoteIdInsertionMap = new Map<ID,ID>();
     
    if(Trigger.isInsert)
    {
        /*integer counter = 1; 
        
        for(QuoteLineItem quoteItemObject : Trigger.New)
        {
            System.debug('The Opportunity Line Item Number in Trigger => '+quoteItemObject.Opportunity_Line_Item_Id__c );
            //Using the Total Quote Item Count Values...
            quoteItemObject.Item_Number__c = quoteItemObject.Total_Number_of_Quote_Item__c + counter;
            //Adding in the counter for the batch Inserting operation...
            counter++;
            
            System.debug('The Quote Line Item Number in Trigger => '+quoteItemObject.Item_Number__c );
            
        }
        */
           
    	for(QuoteLineItem quoteItemObject : Trigger.New)
        {
        	quoteIdInsertionMap.put(quoteItemObject.QuoteId,quoteItemObject.QuoteId);
        	
        }
    
    	if(quoteIdInsertionMap.size() > 0)
    	{
    		for(ID quoteID : quoteIdInsertionMap.keyset())
    		{
    			integer counter = 1; 
        
		        for(QuoteLineItem quoteItemObject : Trigger.New)
		        {
		            if(quoteItemObject.QuoteId == quoteID)
		            {
		            	System.debug('The Opportunity Line Item Number in Trigger => '+quoteItemObject.Opportunity_Line_Item_Id__c );
			            //Using the Total Quote Item Count Values...
			            quoteItemObject.Item_Number__c = quoteItemObject.Total_Number_of_Quote_Item__c + counter;
			            //Adding in the counter for the batch Inserting operation...
			            counter++;
			            
			            System.debug('The Quote Line Item Number in Trigger => '+quoteItemObject.Item_Number__c );	
		            }
		            
		        }		
    		}
    		
    	}
    
    
    }
    
    
    if(Trigger.isDelete)
    {
        
        for(QuoteLineItem quoteItemObject : Trigger.old)
        {
            
            quoteIdMap.put(quoteItemObject.Id,quoteItemObject.QuoteId);
            
        }
        
    }
    
    if(quoteIdMap.size() > 0)
    {
        
        //List<Quote> quoteList = new List<Quote>([Select Id, (Select Item_Number__c From QuoteLineItems) From Quote where Id IN : quoteIdMap.values() ]);
        //Creating the Updating List...
        List<QuoteLineItem> quoteItemUpdateList = new List<QuoteLineItem>();
        
        for(Quote quoteObject : [Select Id, (Select Id,Item_Number__c From QuoteLineItems ORDER BY Item_Number__c ASC) From Quote where Id IN : quoteIdMap.values() ])
        {
            integer counter = 1;
            for(QuoteLineItem quoteItem : quoteObject.QuoteLineItems)
            {
                quoteItem.Item_Number__c = counter;
                
                //Adding the counter...
                counter ++;
                
                //Now Adding in the list...
                quoteItemUpdateList.add(quoteItem);
                
            }
        }
        
        //Now Update the Quote Line Item...
        if(quoteItemUpdateList.size() > 0)
            update quoteItemUpdateList;
            
        
    }
    
}